/*
 * AccountDetailsDialog.java
 * 
 * Dialog in where additional details about the account are displayed.
 * 
 * 
 * Copyright (C) 2008 Fraunhofer SCAI, Germany
 * All rights reserved
 * 
 * https://gforge.beingrid.eu/gf/project/scailm
 */
package de.fraunhofer.scai.lm.gui;

import java.util.List;

import org.apache.log4j.Logger;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;


/**
 * Dialog class showing the licence information.
 * 
 * @version $LastChangedRevision$
 * @author Bea Hornef
 * @author Yona Raekow
 */
public class AccountDetailsDialog extends Dialog {

    /**
     * Additional information of the account.
     */
    private List<String> myDetails;

    /**
     * Name of the account.
     */
    private String myAccountName;

    /**
     * Logger for the AccountDetailsDialog class.
     */
    static Logger logger = Logger.getLogger(AccountDetailsDialog.class);
    		
    /**
     * Constructor.
     * 
     * @param parentShell
     *                the parent shell.
     * @param accountName
     *                the name of the account.
     * @param details
     *                a list of additional details.
     */
    public AccountDetailsDialog(Shell parentShell, String accountName,
	    List<String> details) {
    	super(parentShell);
    	myAccountName = accountName;
    	myDetails = details;
    }

    /**
     * {@inheritDoc}
     * 
     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
     */
    @Override
    protected void createButtonsForButtonBar(Composite parent) {
    	//ok-Button
    	createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    }

    /**
     * {@inheritDoc}
     * 
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
     */
    @Override
    protected void configureShell(Shell newShell) {
    	super.configureShell(newShell);
    	newShell.setText("Account Details");
    }

    /**
     * {@inheritDoc}
     * 
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
     */
    @Override
    protected Control createDialogArea(Composite parent) {

    	Composite composite = (Composite) super.createDialogArea(parent);

		final GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.marginBottom = 10;
		gridLayout.marginRight = 10;
		gridLayout.marginLeft = 10;
		gridLayout.marginTop = 10;
		composite.setLayout(gridLayout);
	
		final Composite logoComposite = new Composite(composite, SWT.NONE);
		logoComposite.setLayout(new GridLayout(2, true));
		
		//SCAI-Logo
		final Label scaiLabel = new Label(logoComposite, SWT.NONE);
		scaiLabel.setLayoutData(new GridData());
		scaiLabel.setImage(SWTResourceManager.getImage(
			TANAndAccountManagementWindow.class,
			"images/SCAI-Logo-small.gif"));
	
		//T-Systems-Logo
		final Label tsystemsLabel = new Label(logoComposite, SWT.NONE);
		tsystemsLabel.setLayoutData(new GridData());
		tsystemsLabel.setImage(SWTResourceManager.getImage(
			TANAndAccountManagementWindow.class,
			"images/T-Systems-Logo-small.jpg"));
		final Label infoTextLabel = new Label(composite, SWT.NONE);
		infoTextLabel.setText("Detailed information about " + myAccountName);
	
		final Composite infoComposite = new Composite(composite, SWT.NONE);
		infoComposite.setLayout(new GridLayout(2, false));
		infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
			false));

		Label[] infoLabel = new Label[myDetails.size()];
		Text[] infoText= new Text[myDetails.size()];
		int i = 0;
		for (Object detail: myDetails) {
           infoLabel[i] = new Label(infoComposite, SWT.NONE);
           infoLabel[i].setText("Info "+ (i+1) +":");
           infoText[i] = new Text(infoComposite, SWT.BORDER);
           infoText[i].setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
           infoText[i].setEditable(false);
           infoText[i].setText(detail.toString());
           i++; 
		}

		composite.pack();
		return composite;
    }

}
